#encoding:utf-8
import copy
object1 = ["Will", 28, ["Python", "C#", "JavaScript"]]
# 对象浅复制
# object2 = copy.copy(object1)
"""
浅复制结果:
print(object1)
print(object2)
['wliiter', 28, ['Python', 'C#', 'JavaScript', 'CSS']]
['Will', 28, ['Python', 'C#', 'JavaScript', 'CSS']]
"""
object2 = copy.deepcopy(object1)
"""深复制结果:
print(object1)
print(object2)
['wliiter', 28, ['Python', 'C#', 'JavaScript', 'CSS']]
['Will', 28, ['Python', 'C#', 'JavaScript']]
"""
# print(object1)
# print(object2)

# 更改objeect1来看object2变化
object1[0] = "wliiter"
object1[2].append("CSS")
print(object1)
print(object2)

"""
深浅复制区别为:浅复制会使用原始元素的内存地址;深复制不使用原始元素的内存地址.
1.浅复制中修改不可变元素的时候会产生一个新的对象;在修改可变元素的时候后不会产生新对象.
2.查看内存地址
print(f"id of object2 {id(object2)}")
print(object2)
print([id(ele) for ele in object2])
结果如下:
id of object2 2574657965896
['Will', 28, ['Python', 'C#', 'JavaScript']]
[2574657732480, 1999030800, 2574657964680]
"""